/**
 *    @file       globaltime.h
 *
 *    @brief      
 *    @details
 *
 *    @version    1.0
 *    @date       02/13/2014 11:42:09 AM
 *
 *    @author     Theophilus (), wangtf418@gmail.com 
 */
#ifndef _BF_GLOBALTIME_H_
#define _BF_GLOBALTIME_H_
#include <string>
#include "comdef.h"
#include "atomic_int.h"
#include "threadrwlock.h"
#include "toolkit.h"

typedef atomic_int<bf_time_t> atomic_time;

class globaltime
{
public:
	globaltime();
	~globaltime();

public:
	inline void settime(bf_time_t curtime)
	{
		m_cur_sec.set(curtime);
		m_gmt_lock.write_lock();
		m_cur_gmt_time = toolkit::sec2httptime(curtime);
		m_gmt_lock.release_lock();
	}

	inline std::string get_gmttime()
	{
		std::string strret;
		m_gmt_lock.read_lock();
		strret = m_cur_gmt_time;
		m_gmt_lock.release_lock();
		return strret;
	}

	inline bf_time_t get_unixtime()
	{
		return m_cur_sec.get();
	}
private:
	static std::string m_cur_gmt_time;
	static threadrwlock m_gmt_lock;
	static atomic_time m_cur_sec;
};


#endif

